package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC739 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int[] dailyTemperatures(int[] temperates) {
            int[] higherDist = new int[temperates.length];
            for (int i = temperates.length - 2; i >= 0; i--) {
                int curDist = 1;
                while (temperates[i] >= temperates[i + curDist]) {
                    if (higherDist[i + curDist] == 0) {
                        curDist = 0;
                        break;
                    }
                    curDist += higherDist[i + curDist];
                }
                higherDist[i] = curDist;
            }

            return higherDist;
        }
    }

    //[1, 1, 4, 2, 1, 1, 0, 0].
    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[73, 74, 75, 71, 69, 72, 76");
        System.out.println(solution.dailyTemperatures(arr));
    }

    public static void main(String[] args) throws Exception {
        LC739 an = new LC739();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
